package com;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Mathias
 */

import java.io.*;
import java.util.*;

public class ReliableDatagram implements Serializable {
    
    private int sequenceNumber = 0;
    private double loss = 0;
    private Serializable data = null;

    public boolean packetLost() {
        int myNumber = 0;
        
        if(this.loss != 0) {
            Random rand = new Random(System.nanoTime());
            myNumber = rand.nextInt(99);
            if (myNumber < ((this.loss * 100) - 1) ) {                
                return false;
            }            
        }

        // paket verwerfen
        return true;
    }

    /**
     * @return the sequenceNumber
     */
    public int getSequenceNumber() {
        return sequenceNumber;
    }

    /**
     * @param sequenceNumber the sequenceNumber to set
     */
    public void setSequenceNumber(int sequenceNumber) {
        this.sequenceNumber = sequenceNumber;
    }


    /**
     * @return the loss
     */
    public double getLoss() {
        return loss;
    }

    /**
     * @param loss the loss to set
     */
    public void setLoss(double loss) {
        this.loss = loss;
    }

    /**
     * @return the data
     */
    public Serializable getData() {
        return data;
    }

    /**
     * @param data the data to set
     */
    public void setData(Serializable data) {
        this.data = data;
    }

   

    
}
